package com.qs.sckill.service.impl;

import com.qs.sckill.dao.GoodsDao;
import com.qs.sckill.dao.SckillGoodsDao;
import com.qs.sckill.entity.SckillGoods;
import com.qs.sckill.service.GoodsService;
import com.qs.sckill.vo.GoodsVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class GoodsServiceImpl implements GoodsService {

    @Autowired
    private GoodsDao goodsDao;

    @Autowired
    private SckillGoodsDao sckillGoodsDao;

    @Override
    public List<GoodsVo> listGoodsVo() {
        return goodsDao.listGoodsVo();
    }

    @Override
    public GoodsVo getGoodsVoByGoodsId(String goodsId) {
        return goodsDao.getGoodsVoByGoodsId(goodsId);
    }

    @Override
    public void reduceStock(GoodsVo goods) {
        SckillGoods sckillGoods = new SckillGoods();
        sckillGoods.setGoodsId(goods.getId());
        sckillGoodsDao.reduceStock(sckillGoods);
    }

    @Override
    public Integer getStockCountByGoodsId(String goodsId) {
        return goodsDao.getStockCount(goodsId);
    }
}
